<html>
<head>
    <script src="jquery/jquery.js"></script>
    <link href="css/css.css" rel="stylesheet" type="text/css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="format-detection" content="telephone=no" />
    <meta charset="utf-8">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>服务地址</title>
    <style>
        /*address地址*/
        .address{ height:78px; padding-left:4%; padding-right:4%; position:relative; margin-top:14px; background-color:#fff; padding-top:9px; box-sizing:border-box}
        .address h1{ font-size:14px; line-height:21px; color:#191919;}
        .address h2{ font-size:14px;  color:#65646b;}
        .address h3{ font-size:14px; line-height:18px; color:#b2bab8;}
        .address p{line-height:41px; position:absolute; right:4%; top:0; background-image:url(images/block.png); background-size:13px 13px; background-position:left center; background-repeat:no-repeat; padding-left:20px;}
        .delete{ width:20%; height:74px; line-height:74px; background-color:#c40000; color:white; font-size:18px; text-align:center; position:absolute; top:0; right:0}
        .update{ width:20%; height:74px; line-height:74px; background-color:#c40000; color:white; font-size:18px; text-align:center; position:absolute; top:0; right:0;}
    </style>
</head>

<body style="background-color: #f9f9f9;">
<!--header顶部标题-->
<div class="header">服务地址
    <div class="header_left"  onclick="window.history.go(-1)"><img src="images/return.png"></div>
    <div class="header_right" id="edit" onClick="onedit()">编辑</div>
</div>
<!--address地址-->
<?php if(session('userinfo')['id']!=null){?>
@foreach($res as $v)
    <div class="address">
        <input type="hidden" value="" id="shuju"/>
        <input type="hidden" value="{{$text}}" id="text"/>
        <div class="border_top"></div>
        @if($sid)
            <div onclick="add({{$v->id}})">
                @else
                    <div>
                        @endif
                        <h1>位置  {{$v->say_id}}</h1>
                        <h2>联系人：<span>{{$v->addname}}</span>&nbsp;&nbsp;&nbsp;&nbsp;电话：<span>{{$v->tel}}</span></h2>
                        <h2>地址：<span>{{$v->dz}}</span></h2>
                    </div>
                @if(!$sid)
                    <div class="delete" data-id="{{$v->id}}">删除</div>
                    <div class="update" update-id="{{$v->id}}">修改</div>
                    <div class="border_bottom"></div>
                    @endif
            </div>
        @endforeach
        <?php }?>
        <!--column添加新地址-->
            <div class="column_box" style="margin-top:14px;" onclick="document.location='address_add';">
                <div class="border_top"></div>
                <div class="column_img"><img src="images/add.png"></div>
                <p>添加新地址</p>
                <div class="next"><img src="images/arrow.png"></div>
                <div class="border_bottom"></div>
            </div>
            <script>
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
                });

                $(".delete").hide();
                function onedit(){
                    var a=document.getElementById('edit').innerText;
                    if(a=="编辑"){
                        $(".delete").show();
                        $(".update").hide();
                        document.getElementById('edit').i}else{
                        nnerText="取消";
                        $(".update").show();
                        $(".delete").hide();
                        document.getElementById('edit').innerText="编辑";
                    }
                }

                $(".delete").click(
                    function(){
                        var id = $(this).attr('data-id');
                        $.ajax({
                            type:"get",
                            url: "address_delete",
                            data: {
                                'id':id,
                            },
                            success:function(data){
                                if(data==1){
                                    $(this).parent().remove();
                                    document.location='address';
                                }
                            }
                        });
                    })

                $(".update").click(
                    function(){
                        var id = $(this).attr('update-id');
                        $.ajax({
                            type:"post",
                            url: "address_uid",
                            data: {
                                'id':id,
                            },
                            success:function(data){
                                document.location='address_update';
                                $(this).parent().remove();
                            }
                        });
                    });

                function add(id){
                    $("#shuju").val(id);
                    var id=$("#shuju").val();
                    var text=$("#text").val();
                    $.ajax({
                        type:'post',
                        url:'cleaning_index',
                        data:{
                            'id':id,
                            'text' :text
                        },
                        success:function(data){
                            if(data["code"] == '1'){
                                document.location="cleaning_index?id="+data['id'];
                            }
                            if(data["code"] == '2'){
                                document.location="floor?text={{$text}}&id="+data['id'];
                            }
                        }
                    });

                }
            </script>
</body>
</html>

